package com.jin.webvideo.base.httpclient;

import org.apache.http.HttpEntity;
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;

import java.net.URI;

public class RequestBase extends HttpEntityEnclosingRequestBase {
    private String method;

    public RequestBase(String uri, String method) {
       this(URI.create(uri), method);
    }

    public RequestBase(URI uri, String method) {
        super();
        setURI(uri);
        this.method = method;
    }

    @Override
    public String getMethod() {
        return this.method;
    }

    @Override
    public void setEntity(HttpEntity entity) {
        if (entity instanceof ParamHttpEntity paramHttpEntity) {
            setURI(paramHttpEntity.getURI(getURI()));
        }
        super.setEntity(entity);
    }
}
